package ysq.xyg.web.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.sys.model.vo.SysDictContentVo;
import ysq.xyg.sys.service.SysDictContentService;
import ysq.xyg.web.model.po.WebOrder;
import ysq.xyg.web.model.po.WebSignUp;
import ysq.xyg.web.model.vo.WebOrderVo;
import ysq.xyg.web.service.WebOrderService;
import ysq.xyg.web.service.WebSignUpService;
import ysq.xyg.web.util.WebBaseContent;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 业务模块-活动订单controller层
 *
 * @author shengQiang yu
 * @date 2019-5-11 10:02:08
 */
@RestController
public class WebOrderController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebOrderController.class);
    @Resource
    private WebOrderService webOrderService;
    @Resource
    private SysDictContentService sysDictContentService;
    @Resource
    private WebSignUpService webSignUpService;

    private WebOrder webOrder;
    /**
     * 跳转到列表页面
     *
     * @param signId 活动id
     * @author shengQiang yu
     * @date 2019-4-26 16:33:55
     */
    @RequestMapping(value = "/webOrder/webOrderList",method = RequestMethod.GET)
    public ModelAndView webOrderList(String signId){
        ModelAndView view = new ModelAndView("/web/webOrderList");
        WebSignUp webSignUp=webSignUpService.selectByPrimaryKey(signId);
        view.addObject("webSignUp", webSignUp);
        view.addObject("signId", signId);
        return view;
    }
    /**
     * 分页查询
     *
     * @param webOrderVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-5-11 10:02:08
     */
    @BaseLog(module = "业务模块",className = "活动订单",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webOrder/page",method = RequestMethod.POST)
    public ReturnEntity page(WebOrderVo webOrderVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webOrderService.page(webOrderVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-11 10:02:08
     */
    @RequestMapping(value = "/webOrder/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webOrderUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webOrder = webOrderService.selectByPrimaryKey(id);
            WebSignUp webSignUp=webSignUpService.selectByPrimaryKey(webOrder.getSignId());
            view.addObject("webSignUp", webSignUp);
            view.addObject("webOrder", webOrder);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-11 10:02:08
     */
    @BaseLog(module = "业务模块",className = "活动订单",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webOrder/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webOrderService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webOrderVo Vo对象
     * @author shengQiang yu
     * @date 2019-5-11 10:02:08
     */
    @BaseLog(module = "业务模块",className = "活动订单",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webOrder/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebOrderVo webOrderVo){
        return webOrderService.addOrUpdate(webOrderVo,acceptCurrentUser(request));
    }
    /**
     * 导出
     *
     * @param webOrderVo Vo对象
     * @author shengQiang yu
     * @date 2019-5-11 10:02:08
     */
    @RequestMapping(value = "/webOrder/export",method = RequestMethod.POST)
    public void export(HttpServletResponse response, WebOrderVo webOrderVo){
        webOrderService.export(response,webOrderVo);
    }

    /**
     * 打印页面
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-11 10:02:08
     */
    @RequestMapping(value = "/webOrder/getPrint",method = RequestMethod.GET)
    public ModelAndView getPrint(String id){
        ModelAndView view = new ModelAndView("/web/webOrderPrintChild");
        webOrder = webOrderService.selectByPrimaryKey(id);
        if(WebBaseContent.WEB_USER_TYPE_CR.equals(webOrder.getUserType())){
            //成人
            view.setViewName("/web/webOrderPrintCr");
        }
        WebSignUp webSignUp=webSignUpService.selectByPrimaryKey(webOrder.getSignId());
        view.addObject("webSignUp", webSignUp);
        view.addObject("webOrder", webOrder);
        return view;
    }
}